<?php
require_once 'MyPdoPublic.class.php';
class TablePublicGoodsType extends MyPdoPublic{
	private $tableName = 'public_goods_type';
	//商品类别的删除 
	public function _goodsTypeDel($id){
		$sql = "delete from {$this->tableName} where id = ? || parent_id = ?";
		$res = $this->dml($sql,array($id,$id));
		if($res){
			return 'ok';
		}else{
			return 'err2';
		}
	}



	//商品类别改名
	public function _goodsTypeChangeName($name,$id){
		$sql = "update {$this->tableName} set name = ? where id =?";
		$res = $this->dml($sql,array($name,$id));
		if($res){
			return 'ok';
		}else{
			return 'err2';
		}
	}



	//商品类别改序
	public function _goodsTypeChangeOrder($order,$id){
		$sql = "update {$this->tableName} set orders = ? where id =?";
		$res = $this->dml($sql,array($order,$id));
		if($res){
			return 'ok';
		}else{
			return 'err2';
		}
	}






	//添加商品类别 
	public function _goodsTypeAdd($level,$parent_id,$name,$order){
		$sql = "select id from {$this->tableName} where level = ? and parent_id = ? and name = ?";
		$res = $this->dql($sql,array($level,$parent_id,$name));
		if(!$res){
			$sql2 = "insert into {$this->tableName}(name,parent_id,level,orders) values(?,?,?,?)";
			$res2 = $this->dml($sql2,array($name,$parent_id,$level,$order));
			if($res2){
				return 'ok';
				
			}else{
				return 'err3';	//添加失败
			}
		}else{
			return 'err2';	//分类已存在
		}	
	}


	//获取商品类别列表
	public function _getGoodsTypeListFull(){
		$sql = "select * from {$this->tableName} order by orders";
		$res = $this->dql($sql,array());
		if($res){
			$data = $res;
		}else{
			$data = array();
		}
		return $data;
	}
}